package com.bazaaroid.server.gae.core.persistence.model.partner;

import java.util.HashSet;
import java.util.Set;

import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;

import com.bazaaroid.server.gae.core.persistence.model.AbstractModel;
import com.google.appengine.api.datastore.Key;

@SuppressWarnings("serial")
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class Product extends AbstractModel {

	@Persistent
	private String name;
	@Persistent
	private String description;
	@Persistent
	private double price;
	@Persistent
	private String currency;
	@Persistent
	private String imagePath;
	@Persistent
	private String barcode;
	@Persistent
	private String localId;
	@Persistent
	private Partner partner;
	@Persistent(defaultFetchGroup = "true")
	private Key discount;
	@Persistent(defaultFetchGroup = "true")
    private Set<Key> locations = new HashSet<Key>();
	@Persistent(defaultFetchGroup = "true")
    private Set<Key> categories = new HashSet<Key>();
	@Persistent(defaultFetchGroup = "true")
    private Set<Key> tags = new HashSet<Key>();

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public double getPrice() {
		return price;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	public String getCurrency() {
		return currency;
	}

	public void setCurrency(String currency) {
		this.currency = currency;
	}

	public String getImagePath() {
		return imagePath;
	}

	public void setImagePath(String imagePath) {
		this.imagePath = imagePath;
	}

	public String getBarcode() {
		return barcode;
	}

	public void setBarcode(String barcode) {
		this.barcode = barcode;
	}

	public String getLocalId() {
		return localId;
	}

	public void setLocalId(String localId) {
		this.localId = localId;
	}

	public Partner getPartner() {
		return partner;
	}

	public void setPartner(Partner partner) {
		this.partner = partner;
	}

	public Key getDiscount() {
		return discount;
	}

	public void setDiscount(Key discount) {
		this.discount = discount;
	}

	public Set<Key> getLocations() {
		return locations;
	}

	public void setLocations(Set<Key> locations) {
		this.locations = locations;
	}

	public void addLocation(Location location) {
	    locations.add(location.getKey());
	    location.getProducts().add(getKey());
	}

	public void removeLocation(Location location) {
		locations.remove(location.getKey());
	    location.getProducts().remove(getKey());
	}

	public Set<Key> getCategories() {
		return categories;
	}

	public void setCategories(Set<Key> categories) {
		this.categories = categories;
	}

	public void addCategory(Category category) {
	    categories.add(category.getKey());
	    category.getProducts().add(getKey());
	}

	public void removeCategory(Category category) {
		categories.remove(category.getKey());
	    category.getProducts().remove(getKey());
	}

	public Set<Key> getTags() {
		return tags;
	}

	public void setTags(Set<Key> tags) {
		this.tags = tags;
	}

	public void addTag(Tag tag) {
	    tags.add(tag.getKey());
	    tag.getProducts().add(getKey());
	}

	public void removeTag(Tag tag) {
		tags.remove(tag.getKey());
	    tag.getProducts().remove(getKey());
	}
}
